const {PrismaClient} = require('@prisma/client');

const prisma = new PrismaClient();


const getById = (id) => {
    return prisma.user.findFirst({
        where: {
            id
        }
    });
}

const getByPhone = async (phone) => {
    return prisma.user.findFirst({
        where: {
            phone
        }
    });
}


const countByPhone = (phone) => {
    return prisma.user.count({
        where: {phone}
    })
}

const createUser = (user) => {
    return prisma.user.create({
        data: user
    });
}

const updateUser = (user) => {
    return prisma.user.update({
        where: {
            id: user.id
        },
        data: user
    });
}

module.exports = {
    getByPhone,
    createUser,
    countByPhone,
    getById,
    updateUser
}